# rename.py
# 将文件和对应的标签重命名为从六位数的名字，从000001开始，注意：图片和标签都需要进行重命名

import os

# path = "C:/Users/yanbo/Desktop/highway_diseases/jpg"  # json标签文件的保存路径
path = 'C:/Users/yanbo/Desktop/highway_diseases/json'  # json文件路径
filelist = os.listdir(path)
count = 1
for file in filelist:
    print(file)
for file in filelist:
    Olddir = os.path.join(path, file)
    if os.path.isdir(Olddir):
        continue
    filename = os.path.splitext(file)[0]
    filetype = os.path.splitext(file)[1]
    Newdir = os.path.join(path, str(count).zfill(6) + filetype)  # zfill(6):表示命名为6位数
    os.rename(Olddir, Newdir)

    count += 1

